﻿using CommunityToolkit.WinUI.Collections;
using DimensionsHelper.Client.WinUi.Contracts;

namespace DimensionsHelper.Client.WinUi.Models;

public partial class StringMapCollection(List<StringMap> source, IEnumerable<string> keys) :
    IncrementalLoadingCollection<IIncrementalSource<StringMap>, StringMap>(new IncrementalLoadingSource(source)),
    IStringKeysAvailable
{
    private readonly string[] _keys = keys.ToArray();


    public string[] GetKeys() => _keys;


    private class IncrementalLoadingSource(List<StringMap> source) : IIncrementalSource<StringMap>
    {
        public Task<IEnumerable<StringMap>> GetPagedItemsAsync(int pageIndex, int pageSize,
            CancellationToken cancellationToken = default) =>
            Task.Run(() => source.Skip(pageIndex * pageSize).Take(pageSize), cancellationToken);
    }
}